<template>
	<view class="page tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="top-bg"></view>
		<dawnBar title="电子健康卡"></dawnBar>
		<view class="page-container" style="padding-bottom: 180rpx;">
			<view class="order--wrap">
				<view class="card-box" v-for="(item,index) in list" :key="index">
					<view class="card-box__content" @click="navLink(item)">
						<view class="card-box__content__data ">
							<view class="card-box__content__data__name">{{item.name}}</view>
							<view class="card-box__content__data__no">{{item.cardNo_}}</view>
						</view>
						<image class="card-box__content__image" src="../../static/images/eh-qrcode.jpg" mode="aspectFit"></image>
					</view>
				</view>
				
				<!-- 悬浮按钮-->
				<view class="tn-flex tn-footerfixed">
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<tn-button @click="addEHealth" class="dawn-btn-lg dawn-btn-lg__eh">
							<text class="tn-icon-add tn-padding-right-xs"></text>
							<text>添加健康卡</text>
						</tn-button>
						<view class="tn-margin-top-ss">
							<text class="dawn-color-grey">您还可以添加 {{ canNum }} 张健康卡</text>
						</view>
					</view>
				</view>
			</view>
			<view v-if="show">
				<view class="dawn-success">
					<image mode="aspectFit" class="dawn-success__image" src="../../static/images/eh-nocard.png"></image>
					<view class="dawn-success__title">
						暂无健康卡
					</view>
				</view>
			</view>
		</view>

		<!-- loading -->
		<dawnLoading :show="loading"></dawnLoading>

		<!-- 分页 -->
		<!-- <dawn-pagination ref="pagination" :current="queryData.pageNo" :total="total" @pagination="getPage" /> -->

		<!-- 悬浮按钮-->
		<NavBtn></NavBtn>
	</view>
</template>

<script>
	import page_mixin from '@/mixins/page_mixin.js'
	import dayjs from '@/plugin/dayjs/dayjs.min.js';
	import * as PatientApi from '@/api/hospital/patient.js';
	import * as api from '@/api/api.js';
	import * as config from "@/api/config.js";
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
  import {eHealthList} from "../../api/hospital/patient";
	const app = getApp();

	export default {
		name: 'order',
		mixins: [page_mixin],
		computed: mapGetters(['appConfig', 'uid', 'isLogin', 'userInfo', 'patientInfo']),
		data() {
			return {
				loading: false,
				show: false,
				msg: '',
				queryData: {
					pageSize: 10,
					pageNo: 1,
					userId: ''
				},
				list: [],
				canNum: 5,
			}
		},
		onLoad(options) {
			if (!this.isLogin) {
				toLogin();
				return;
			} else {
				this.getPage();
			}
		},
		methods: {
			getPage: function(page) {
				let that = this;
				this.loading = true;
				this.show = false;
				this.$set(this, 'list', []);
				// this.queryData.userId = app.globalData.openid;
				this.queryData.userId = this.userInfo.openid;
				PatientApi.eHealthList(this.queryData).then(res => {
					this.loading = false;
					if (res.code === 0) {
						const l = res.data || [];
						// const l = [];
						this.$set(this, 'list', l);
						if (l.length == 0) {
							this.show = true;
						}
						that.canNum = 5 - l.length;
					} else {
						this.show = true;
						this.msg = res.msg;
					}
				}).catch(err => {
					this.loading = false;
					this.show = true;
				})
			},
			navLink(item) {
				// uni.navigateTo({
				// 	url: url
				// })
				this.$util.setStorageData(config.STORE_KEY.P_DETAIL, {
					'itemId': item.id
				});
				uni.navigateTo({
					url: '/hosp/ehealth/detail'
				})
			},
			formatDate: function(date) {
				return dayjs(date).format("YYYY-MM-DD");
			},
			formatDateTime: function(date) {
				return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>